package com.service.impl;

import com.bean.entity.ProductSpecification;
import com.bean.vo.ChainTypeQueryVo;
import com.bean.vo.ProductInfomationQueryVo;
import com.dao.ChainTypeMapper;
import com.dao.ProductSpecificationMapper;
import com.service.ProductInfomationService;
import com.service.ProductSpecificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
public class ProductSpecificationServiceImpl implements ProductSpecificationService {
    @Autowired
    private ProductSpecificationMapper psm;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long add(ChainTypeQueryVo ctv) {
        ProductSpecification ps = ctv.getPs();
        List<ProductSpecification> list = psm.selectEntity(ps);
        if (list.size()!=0){
            Long id = list.get(0).getId();
            return id;
        }
        psm.insertMain(ps);
        List<ProductSpecification> list2 = psm.selectEntity(ps);
        Long id = list2.get(0).getId();
        return id;
    }

    @Override
    public Long add(ProductInfomationQueryVo piqv) {
        ProductSpecification ps = piqv.getPs();
        List<ProductSpecification> list = psm.selectEntity(ps);
        if (list.size()!=0){
            Long id = list.get(0).getId();
            return id;
        }
        psm.insertMain(ps);
        List<ProductSpecification> list2 = psm.selectEntity(ps);
        Long id = list2.get(0).getId();
        return id;
    }

    @Override
    public Long update(ChainTypeQueryVo ctv) {
        ProductSpecification ps = ctv.getPs();
        List<ProductSpecification> list = psm.selectEntity(ps);
        if (list.size()!=0){
            Long id = list.get(0).getId();
            return id;
        }
        psm.insertMain(ps);
        List<ProductSpecification> list2 = psm.selectEntity(ps);
        Long id = list2.get(0).getId();

        return id;
    }

    @Override
    public Long update(ProductInfomationQueryVo piqv) {
        ProductSpecification ps = piqv.getPs();
        List<ProductSpecification> list = psm.selectEntity(ps);
        if (list.size()!=0){
            Long id = list.get(0).getId();
            return id;
        }
        psm.insertMain(ps);
        List<ProductSpecification> list2 = psm.selectEntity(ps);
        Long id = list2.get(0).getId();

        return id;
    }
}
